package com.leantech.android.browser.utils

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.coroutineScope
import androidx.lifecycle.withResumed
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

private const val waitDuration = 100L

fun FragmentActivity.awaitSplashAd(onResumeFromSplashAd: () -> Unit) {
    lifecycle.coroutineScope.launch {
        delay(waitDuration) //delay wait for hot launcher activity start.
        lifecycle.withResumed {
            onResumeFromSplashAd()
        }
    }
}

fun Fragment.awaitSplashAd(onResumeFromSplashAd: () -> Unit) {
    lifecycle.coroutineScope.launch {
        delay(waitDuration)
        lifecycle.withResumed {
            onResumeFromSplashAd()
        }
    }
}
